feat(span-streaming): Add span batcher (2)#5398
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Span Streaming
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 14 passed | Total: 14 | Pass Rate: 100% | Execution Time: 3.66s All tests are passing successfully. ❌ Patch coverage is 33.33%. Project has 14761 uncovered lines. Files with missing lines (181)
Generated by Codecov Action |
| "sent_at": format_timestamp(datetime.now(timezone.utc)), | ||
| "trace": dsc, | ||
| } | ||
| ) |
There was a problem hiding this comment.
Envelope header unconditionally includes null trace context
Low Severity
The _flush method unconditionally includes "trace": dsc in envelope headers even when dsc is None. This results in "trace": null in the serialized JSON. The established pattern elsewhere in the codebase (e.g., in client.py around line 909) is to only include the trace header when the dynamic sampling context is truthy. Including a null trace header is inconsistent and could potentially cause issues with the Sentry backend when this experimental feature is enabled.
There was a problem hiding this comment.
All coming in future PRs
alexander-alderman-webb
left a comment
There was a problem hiding this comment.
looks good! just one question from me, not blocking
| self._flusher_pid: "Optional[int]" = None | ||
|
|
||
| def get_size(self) -> int: | ||
| # caller is responsible for locking before checking this |
There was a problem hiding this comment.
why can we not, or should we not, lock for the caller here?
There was a problem hiding this comment.
The add() function that needs to call this needs to lock a bigger chunk of code including this check and it can't really be split apart.
get_size() is now only used from add(), but if we ever need to use it from elsewhere too, I think it's likely that that place will also need to already be holding a lock if it's doing anything that depends on the current size of the buffer, so it makes sense that the responsibility to lock would be on the caller.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| if TYPE_CHECKING: | ||
| from typing import Any, Callable, Optional | ||
| from sentry_sdk.traces import StreamedSpan | ||
| from sentry_sdk._types import SerializedAttributeValue |
There was a problem hiding this comment.
| FLUSH_WAIT_TIME = 5.0 | ||
|
|
||
| TYPE = "span" | ||
| CONTENT_TYPE = "application/vnd.sentry.items.span.v2+json" |


SpanBatcherthat batches and sends spans by trace ID. Hook it up to the client.StreamedSpanclass that will eventually replace the currentSpanclass.Chipping away at #5317 to transform it into reviewable and mergeable PRs.